package com.fw.ui.view.settings.usercontrol.parentmerchant.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.service.parentmerchant.bean.ParentMerchantBean;
import com.fw.ui.ApplicationUI;
import com.fw.ui.bao.PropertyBAO;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.event.AbstractButtonClickListener;
import com.fw.ui.view.settings.usercontrol.parentmerchant.SearchParentMerchantView;
import com.fw.ui.view.settings.usercontrol.parentmerchant.ViewParentMerchantView;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinService;
import com.vaadin.ui.Button.ClickEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class SearchParentMerchantTableViewButtonClickListener extends AbstractButtonClickListener {

    private static final long serialVersionUID = 1L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;
    @Autowired
    private PropertyBAO propertyBAO;

    @Override
    public Map<String, Object> click(ClickEvent event) throws Exception {
	SearchParentMerchantView searchParentMerchantView = (SearchParentMerchantView) this.getBasedComponent();

	ParentMerchantBean parentMerchantBean = (ParentMerchantBean) event.getButton().getData();
	VaadinService.getCurrentRequest().setAttribute(ViewParentMerchantView.VIEW_PARENT_MERCHANT_ID_REQUEST_ATTRIBUTE,
		parentMerchantBean.getId());

	Navigator navigator = ((ApplicationUI) searchParentMerchantView.getUI()).getNavigator();
	String landing = propertyBAO.getPropertyValue("view.settings-user-control-parentmerchant-view.path");
	navigator.navigateTo(landing);
	return null;
    }

    @Override
    public boolean validate(ClickEvent event) {

	return true;
    }

}
